﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Phone.BackgroundAudio;

namespace SAFPodcast.WP8.Fwk.BackgroundAudio
{
    public static class BackgroundAudioPlayerExtensions
    {
        public static void PlayTrack(this BackgroundAudioPlayer instance, Uri uri, String title, String artist, String album, Uri cover = null)
        {
            if (instance.CanPause)
            {
                EventHandler er = null;
                er = (src, e) =>
                {
                    instance.PlayStateChanged -= er;
                    instance.Track = new AudioTrack(
                        uri,
                        title,
                        artist,
                        album,
                        cover);
                    instance.Play();
                };
                instance.Pause();
                instance.PlayStateChanged += er;
            }
            else
            {
                instance.Track = new AudioTrack(
                    uri,
                    title,
                    artist,
                    album,
                    cover);
                instance.Play();
            }
        }
    }
}
